<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>驴友天地</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="<%=path %>/style/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="<%=path %>/style/indexadd.css" rel="stylesheet" type="text/css" />
<script src="<%=path %>/script/jquery-1.7.2.min.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){

//首先将#back-to-top隐藏

 $("#back-to-top").hide();

//当滚动条的位置处于距顶部100像素以下时，跳转链接出现，否则消失

$(function () {
$(window).scroll(function(){
if ($(window).scrollTop()>100){
$("#back-to-top").fadeIn(1500);
}
else
{
$("#back-to-top").fadeOut(1500);
}
});

//当点击跳转链接后，回到页面顶部位置

$("#back-to-top").click(function(){
$('body,html').animate({scrollTop:0},1000);
return false;
});
});
});


//页面初始化*******************************
//全局变量
var userid="";
var dd="";
var listmem;
var nowuser;
var memnum=0;
//初始化旅游记忆导读
function inituserid(){
	$.ajax({
		type:"post", //请求方式
		url:"<%=path %>/getNowSession", //发送请求地址
		data:{ //发送给数据库的数据
		},
		//请求成功后的回调函数有两个参数
		success:function(data,textStatus){
			if(!data && typeof(data)!="undefined" && data!=0){
			}
			else{
		  		nowuser = eval("("+data+")");
				userid=nowuser.user_id;
				userinfoinit();
				refresh();
				var loopp = setInterval("refresh()",10000);
			}
		}
	});
}
//初始化个人信息
function logout(){
	location.href="<%=path %>/deleteSession";
}
function userinfoinit(){
	$('#login').css("display","none");
	$('#userinfo').css("display","block");	
	$('#personalnav').css("display","block");
	var as="";
	as = as + "<img class='nameimg' src='<%=path %>/"+nowuser.user_headphoto+"' />";
	as = as + "<a href='javascript:void(0);'><span id='name'>"+nowuser.user_name+"</span></a>";
	as = as + "<div id='userintro'>";
	as = as + "<p><input type='button' id='sixin' value='私信' onclick='gotomysixin()' /><input type='button' value='退出' onclick='logout()' /></p>";
	as = as + "<p>"+nowuser.user_location+"</p>";
	as=as+"<p>粉丝数："+nowuser.followed_num+"</p>";
	as=as+"</div>";
	as=as+"<div id='shortintro'>";
	as=as+"<p>爱好："+nowuser.user_hobby+"</p>";
	as=as+"<p>"+nowuser.user_motto+"</p>";
	as=as+"<br /><input type='button' value='发布旅游记忆' style='margin-left:30px;' onclick='writememo()' />";
	as=as+"<input type='button' value='发布结伴游信息' onclick='writetog()' />";		
	as=as+"</div>";
	//alert(as);
	$('#userinfo').append(as);
}
//
function init(){
	inituserid();
	postall();
	hotmem();
	hothuman();
}
function postall(){
	$.ajax({
		type:"post", //请求方式
		url:"<%=path %>/getIndex", //发送请求地址
		data:{ //发送给数据库的数据
		},
		//请求成功后的回调函数有两个参数
		success:function(data,textStatus){
			listmem = eval("("+data+")");
			var num=0;
			if(listmem.length>5){
				num=5;
			}else{
				num=listmem.length;
			}
			for(var i=0;i<num; i++){
				initpost(i);			
			}
		}
	});
}
function morepost(){
	if (listmem.length-memnum>=3){
		for(var i=0;i<3;i++){
			initpost(memnum-1);
		}
	}
	else if(listmem.length-memnum>0){
		for(var i=0;i<listmem.length-memnum;i++){
			initpost(memnum-1);
		}
	}else{
		alert("没有更多内容了");
	}
}
function initpost(i){
	dd=dd+"<div class='post'>";
	dd=dd+"<h2 class='title'><a href='<%=path %>/viewTripMemoryDetail?memoryid="+listmem[i].memory_id+"'>"+listmem[i].memory_title+"</a></h2>";
	dd=dd+"<p class='meta'>"+listmem[i].memory_date.year+"-"+listmem[i].memory_date.month+"-"+listmem[i].memory_date.day+"&nbsp;&nbsp;&nbsp;"+listmem[i].memory_date.hours+":"+listmem[i].memory_date.minutes+":"+listmem[i].memory_date.seconds+"&nbsp;&nbsp;&nbsp;"+" Posted by <a href='javascript:void(0)'>"+listmem[i].user_name+"</a></p><img src='<%=path %>/"+listmem[i].user_picture+"' />";
	dd=dd+"<div class='entry'>";
	dd=dd+"<p>"+listmem[i].memory_content+"</p><p></p>";
	//dd=dd+"<p>Sed lacus. Donec lectus. Nullam pretium nibh ut turpis. Nam bibendum. In nulla tortor, elementum ipsum. Proin imperdiet est. Phasellus dapibus semper urna. Pellentesque ornare, orci in felis. </p>";
	dd=dd+"</div>";
	dd=dd+"</div>";
	$('#contentinpost').append(dd);
	memnum++;
//	alert(listmem[i].user_picture);
}

//热门旅游记忆生成
function hotmem(){
	$.ajax({
		type:"post", //请求方式
		url:"<%=path %>/getTopMemorys", //发送请求地址
		data:{ //发送给数据库的数据
		},
		//请求成功后的回调函数有两个参数
		success:function(data,textStatus){
			var hotlistmem = eval("("+data+")");
			var num=0;
			if(hotlistmem.length>=8){
				num=8;
			}else{
				num=hotlistmem.length;
			}
			for(var i=0;i<num; i++){
				var ss="<li><a href='<%=path %>/viewTripMemoryDetail?memoryid="+hotlistmem[i].tripmemory_id+"'>"+hotlistmem[i].tripmemory_title+"</a></li>";
				$('#hot').append(ss);		
			}
		}
	});
}

//驴友之星初始化
function hothuman(){
	$.ajax({
		type:"post", //请求方式
		url:"<%=path %>/getTripStar", //发送请求地址
		data:{ //发送给数据库的数据
		},
		//请求成功后的回调函数有两个参数
		success:function(data,textStatus){
			var hotlisthuman = eval("("+data+")");
			var num=0;
			if(hotlisthuman.length>6){
				num=6;
			}else{
				num=hotlisthuman.length;
			}
			for(var i=0;i<num; i++){
				var ss="";
				ss=ss+"<li><div class='substars'><img src='<%=path %>/"+hotlisthuman[i].user_headphoto+"' /><div class='starsintro'>";
				ss=ss+"<a href='otherindex.jsp'>"+hotlisthuman[i].user_name+"</a><br />";
				ss=ss+"<span>关注:"+hotlisthuman[i].followed_num+"</span><br />";
				ss=ss+"<span>"+hotlisthuman[i].user_motto+"</span>";
				ss=ss+"</div></div></li>";
				$('#stars').append(ss);
			}
		}
	});
}

//发布链接
function writememo(){
	window.location.href="<%=path %>/page/writemem.jsp";
}
function writetog(){
	window.location.href="<%=path %>/page/writetogether.jsp";
}

//==========================================
//右边浮动框****************************************
function opensxmini(){
	$('#sxmini').css("display","block");
	$('#sxminiclo').css("display","block");
	closecommentmini();
}
function opencommentmini(){
	$('#commentmini').css("display","block");
	$('#commentminiclo').css("display","block");
	closesxmini();
}
function closesxmini(){
	$('#sxmini').css("display","none");
	$('#sxminiclo').css("display","none");
}
function closecommentmini(){
	$('#commentmini').css("display","none");
	$('#commentminiclo').css("display","none");
}
function refresh(){
	sxajax();
	reflectajax();
}
function sxajax(){
	$.ajax({
		type:"post", //请求方式
		url:"<%=path %>/getUnreadMessage", //发送请求地址
		data:{ //发送给数据库的数据
		},
		//请求成功后的回调函数有两个参数
		success:function(data,textStatus){
			 var dataobj = eval("("+data+")");
			 var ss = "";
			 for(var i=0;i<dataobj.length;i++){
				 ss = ss+"<li><span><a href='<%=path %>/getUserIndexById?userid="+dataobj[i].sendid+"' target='_blank'>"+dataobj[i].sendername+"</a>来信<a href='<%=path %>/viewMessageDetail?messageid="+dataobj[i].messageid+"' target='_blank'>"+dataobj[i].messagetitle+"</a></span></li>";
			 }
			 $('#sxminiin').html(ss);
			 $('#sxnuminit').html("("+dataobj.length+")");
		}
	});
}
function reflectajax(){
	$.ajax({
		type:"post", //请求方式
		url:"<%=path %>/getUnreadComment", //发送请求地址
		data:{ //发送给数据库的数据
		},
		//请求成功后的回调函数有两个参数
		success:function(data,textStatus){
			 var dataobj = eval("("+data+")");
			 var ss = "";
			 for(var i=0;i<dataobj.length;i++){
				 ss = ss+"<li><span><a href='<%=path %>/getUserIndexById?userid="+dataobj[i].commenterid+"' target='_blank'>"+dataobj[i].commentername+"</a>在文章<a href='<%=path %>/viewTripMemoryDetail?memoryid="+dataobj[i].passageid+"' target='_blank'>"+dataobj[i].passagetitle+"</a>中回复了你</span></li>";
			 }
			 $('#commentminiin').html(ss);
			 $('#reflectnuminit').html("("+dataobj.length+")");
		}
	});
}

//===========================
//登陆*****************************
function login(){
	loginright();
}
function loginright(){
//alert(11);
	var mail = document.getElementById('username').value;
	var pass = document.getElementById('password').value;
	$.ajax({
		type:"post", //请求方式
		url:"<%=path %>/login", //发送请求地址
		data:{ //发送给数据库的数据
		username:mail,
		password:pass
		},
		//请求成功后的回调函数有两个参数
		success:function(data,textStatus){
			if(data.toString()=="true"){
				inituserid();
			}else if(data.toString()=="false"){
				alert('请输入正确的密码');
			}else{
				alert('用户名不存在');
			}
		}
	});
}

//=================================
//注册****************************
function regis(){
	$('#register').css("display","block");
	$('#shadow').css("display","block");	
}
function cancelreg(){
	$('#register').css("display","none");
	$('#shadow').css("display","none");
	var a = document.getElementById('regmail').innerHTML;
	var b = document.getElementById('regpass').innerHTML;
	var c = document.getElementById('regpass2').innerHTML;
	a="";
	b="";
	c="";
}
function emailright(){
	var mail = document.getElementById('regemail').value;
	//register logic
	$.ajax({
		type:"post", //请求方式
		url:"<%=path %>/registerAjax", //发送请求地址
		data:{ //发送给数据库的数据
		regemail:mail,
		},
		//请求成功后的回调函数有两个参数
		success:function(data,textStatus){
			if(data=="false"){
				$('#1right').css("display","block");
				$('#1error').css("display","none");
			}else{
				$('#1right').css("display","none");
				$('#1error').css("display","block");
			}
		}
	});
}
function passright(){
	var pass = document.getElementById('regpass').value;
	var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(#)($)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);      
    if ( (!containSpecial.test(pass))&&pass.length>5&&pass.length<17 ){
    	$('#2right').css("display","block");
		$('#2error').css("display","none");
    }else{
    	$('#2right').css("display","none");
		$('#2error').css("display","block");
    }
}
function passright2(){
	var pass = document.getElementById('regpass').value;
	var pass2 = document.getElementById('regpass2').value;
	if(pass==pass2&&pass2!=""){
		$('#3right').css("display","block");
		$('#3error').css("display","none");
		document.getElementById('registerbtn').removeAttribute("disabled");
	}else{
		$('#3right').css("display","none");
		$('#3error').css("display","block");	
		document.getElementById('registerbtn').setAttribute("disabled","disapled");
	}
}
function regsubmit(){
	var mail = document.getElementById('regemail').value;
	var pass = document.getElementById('regpass').value;
	location.href="<%=path %>/register?regemail="+mail.toString()+"&regpass="+pass.toString()+"";
}
//================================


</script>

<body onload="init()">
	<div id="logo">
		<h1><a href="#">驴友天地</a></h1>
		<p><em> template design by team Forever</a></em></p>
	</div>
	<hr />
	<!-- end #logo -->
	<div id="header">
		<div id="menu">
			<ul>
				<li><a href="<%=path %>/page/index.jsp" class="first">首页</a></li>
				<li><a href="<%=path %>/page/myindex.jsp">我的</a></li>
				<li><a href="<%=path %>/page/friend.jsp">好友&nbsp;</a></li>
				<li><a href="<%=path %>/page/follow.jsp">关注&nbsp;</a></li>
				<li><a href="<%=path %>/page/together.jsp">结伴游</a></li>
				<li><a href="<%=path %>/page/personal.jsp">个人中心</a></li>
			</ul>
		</div>
		<!-- end #menu -->
		<div id="search">
			<form method="get" action="">
				<fieldset>
				<input type="text" name="s" id="search-text" size="15" />
				<input type="submit" id="search-submit" value="GO" />
				</fieldset>
			</form>
		</div>
		<!-- end #search -->
	</div>
	<!-- end #header -->
	<!-- end #header-wrapper -->
	<div id="page">
		<div id="content">
		<div id="contentinpost">
		</div>
		<input type="button" value="更多" onclick="morepost()" style="margin-left:280px;width:80px;font-size:16px;" />
		</div><!-- end #content -->
		<div id="sidebar">
			<ul>
				<li id="login">
							<h2>请登录</h2>
							<div style="margin-left:30px;">
								<table>
									<tr>
										<td><span>邮箱</span></td>
										<td><input type="text" id="username" width="90px;"/></td>	
									</tr>
									<tr>
										<td><span>密码</span></td>
										<td><input type="password" id="password" width="90px;"/></td>	
									</tr>
									<tr>
										<td></td>
										<td style="text-align:right;"><input type="button" value="登陆" style="width:60px;text-align:center;" onclick="login()" /><input type="button" value="注册" onclick="regis()" style="width:60px;text-align:center;margin-left:10px;" /></td>	
									</tr>
								</table>
							</div>
				</li>
				<li id="userinfo" style="height:200px;">
					<!--  <img class="nameimg" src="<%=path %>/images/test.png" />
					<a href="javascript:void(0);"><span id="name">赵安卡</span></a>
					<div id="userintro">
						<p><input type="button" id="sixin" value="私信" /></p>
						<p>北京,海淀</p>
						<p>email@bjtu.edu.cn</p>
					</div>
					<div id="shortintro">
						<p>爱好：编程序</p>
						<p>签名：喜欢旅行带来的好心情</p>
						<br /><input type="button" value="发布旅游记忆" style="margin-left:30px;" onclick="writememo()" />
							<input type="button" value="发布结伴游信息" onclick="writetog()" />
						
					</div>
					-->
					
				</li>
				<li>
					<h2>热门旅游记忆</h2>
					<ul id="hot">
					<!-- <li><a href="javascript:void(0);">Nec metus sed donec</a></li>-->

					</ul>
				</li>
				<li>
					<h2>驴友之星</h2>
					<div>
					<ul id="stars">
						
						<!-- <li>
							<div class="substars">
								<img src="images/test2.png" />
								<div class="starsintro">
									<a href="page/otherindex.jsp">Nec metus sed donec</a><br />
									<span>关注:1314</span><br />
									<span>喜欢骑自行车</span>
								</div>
							</div>
						</li> -->
						
					</ul>
				</div>
				</li>
			</ul>
		</div>
		<!-- end #sidebar -->
		<div style="clear: both;">&nbsp;</div>
	</div>
	<!-- end #page -->
	<div id="footer">
		<p>Copyright (c) 2012 lvyou.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
	</div>
	<!-- end #footer -->
	<div id="register" >
		<h2>注册</h2>
		<table id="regtable">
			<tr>
				<td>
					<span>邮箱：</span>
				</td>
				<td>
					<span><input type="mail" id="regemail" style="width:130px;" onblur="emailright()" />
				</td>
				<td id="ifemail" style="width:30px;"><img id="1right" class="titlepng" src="<%=path %>/images/right.png" /><img class="titlepng" id="1error" src="<%=path %>/images/error.png" /></td>
			</tr>
			<tr>
				<td>
					<span>密码：</span>
				</td>
				<td>
					<input type="password" id="regpass" style="width:130px;" onblur="passright()" />
				</td>
				<td id="ifpass" style="width:30px;"><img id="2right" class="titlepng" src="<%=path %>/images/right.png" /><img class="titlepng" id="2error" src="<%=path %>/images/error.png" /></td>
			</tr>
			<tr>
				<td>
					<span>确认密码：</span>
				</td>
				<td>
					<input type="password" id="regpass2" style="width:130px;" onkeyup="passright2()" />
				</td>
				<td id="ifpass2" style="width:30px;"><img id="3right" class="titlepng" src="<%=path %>/images/right.png" /><img class="titlepng" id="3error" src="<%=path %>/images/error.png" /></td>
			</tr>
			<tr><td></td><td><br /><input type="button" id="registerbtn" value="提交" style="width:60px;" onclick="regsubmit()" disabled="disabled" /><input type="button" id="cancel" value="取消" style="width:60px;margin-left:16px;" onclick="cancelreg()" /></td></tr>
		</table>
	</div>
	<div id="shadow"></div>
	<div id="personalnav" style="display:none">
		<ul>
			<li>
				<span onclick="opensxmini()"><a href="javascript:void(0)">私信</a></span><span id="sxnuminit"></span>
			</li>
			<li>
				<span onclick="opencommentmini()"><a href="javascript:void(0)">回复</a></span><span id="reflectnuminit"></span>
			</li>
		</ul>
	</div>
	<div id="sxmini">
		<ul id="sxminiin">
			<!--<li>
				<span><a href="page/otherindex.jsp" target="_blank">赵安卡</a>来信<a href="page/sxdetail.jsp" target="_blank">你好我想认识你</a></span>
			</li>-->

		</ul>
	</div>
	<div id="commentmini">
		<ul id="commentminiin">
			<!--  <li>
				<span><a href="page/otherindex.jsp" target="_blank">赵安卡</a>在<a href="page/detail.jsp" target="_blank">北京三日游</a>中回复了你</span>
			</li>-->

		</ul>
	</div>
	<div id="sxminiclo" onclick="closesxmini()"><img src="<%=path %>/images/closebtn.png"  /></div>
	<div id="commentminiclo" onclick="closecommentmini()"><img src="<%=path %>/images/closebtn.png"  /></div>
	<p id="back-to-top"><a href="#top"><span></span></a></p>
</body>
</html>